import { MutationTree } from 'vuex';
import { MutationTypes } from "./mutation-types";
import { CommonState } from "./types";
import storage from 'store';

export type Mutations<S = CommonState> = {
  [MutationTypes.SET_MENU](state: S, payload: MenuItemVO[]): void
  [MutationTypes.REMOVE_MENU](state: S): void
}

export const mutations: MutationTree<CommonState> & Mutations = {
  [MutationTypes.SET_MENU](state, payload) {
    state.menu = payload
    storage.set(MutationTypes.SET_MENU, payload);
  },
  [MutationTypes.REMOVE_MENU](state) {
    state.menu = []
    storage.remove(MutationTypes.SET_MENU);
  },
}